home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / msdos / lynx / source / doslynx / src / memstrat.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-25  |  2.4 KB  |  81 lines

  1. //    Copyright (c) 1994, University of Kansas, All Rights Reserved
  2. //
  3. //    Class:        none
  4. //    Include File:    memstrat.h
  5. //    Purpose:    Set or get the msdos memory allocation strategy.
  6. //    Remarks/Portability/Dependencies/Restrictions:
  7. //        Based on an MS-DOS 3.0 DOS interrupt function.
  8. //        Can only be used with DOS 3.0 or higher.
  9. //    Revision History:
  10. //        04-20-94    created
  11. #include"memstrat.h"
  12. #include<dos.h>
  13.  
  14. extern StrategyType getMemoryAllocationStrategy()    {
  15. //    Purpose:    Return the type of strategy that DOS is currently
  16. //            using to allocate memory.
  17. //    Arguments:    void
  18. //    Return Value:    StrategyType    firstFit    This is the default
  19. //                            DOS allocation
  20. //                            strategy, finding the
  21. //                            first available peice
  22. //                            of memory that will
  23. //                            hold the size
  24. //                            requested.
  25. //                    bestFit        This finds the heap
  26. //                            chunk closest in size
  27. //                            to the requested
  28. //                            amount.
  29. //                    lastFit        Like firstFit, but
  30. //                            starts at the end of
  31. //                            the heap.
  32. //    Remarks/Portability/Dependencies/Restrictions:
  33. //        DOS 3.0 or greater.
  34. //    Revision History:
  35. //        04-20-94    created
  36.  
  37.     auto REGS R_in, R_out;
  38.  
  39.     //    First, clear out our two REGS.
  40.     for(signed short int ssi_counter = 0; ssi_counter < sizeof(REGS);
  41.         ssi_counter++)    {
  42.         *((char *)(&R_in) + ssi_counter) = 0;
  43.         *((char *)(&R_out) + ssi_counter) = 0;
  44.     }
  45.  
  46.     //    Set up R_in for the call.
  47.     R_in.h.ah = (unsigned char)0x58;
  48.     R_in.h.al = (unsigned char)0x0;
  49.  
  50.     //    Return the AX register which values directly correlate to
  51.     //    the enumeration of StrategyType.
  52.     return((StrategyType)int86(0x21, &R_in, &R_out));
  53. }
  54.  
  55. extern void setMemoryAllocationStrategy(const StrategyType ST_fit)    {
  56. //    Purpose:    Set the DOS memory allocation strategy.
  57. //    Arguments:    ST_fit    The type of strategy to have DOS begin
  58. //                employing.
  59. //    Return Value:    void
  60. //    Remarks/Portability/Dependencies/Restrictions:
  61. //        Works only with DOS 3.0 or higher.
  62. //    Revision History:
  63. //        04-20-94    created
  64.  
  65.     auto REGS R_in, R_out;
  66.  
  67.     //    First, clear out our two REGS.
  68.     for(signed short int ssi_counter = 0; ssi_counter < sizeof(REGS);
  69.         ssi_counter++)    {
  70.         *((char *)(&R_in) + ssi_counter) = 0;
  71.         *((char *)(&R_out) + ssi_counter) = 0;
  72.     }
  73.  
  74.     //    Set up R_in for the call.
  75.     R_in.h.ah = (unsigned char)0x58;
  76.     R_in.h.al = (unsigned char)0x1;
  77.     R_in.x.bx = (unsigned short int)ST_fit;
  78.  
  79.     //    Invoke the DOS interrupt to perform the setting of the scheme.
  80.     int86(0x21, &R_in, &R_out);
  81. }